package edu.buffalo.cse.cse486_586.simpledynamo.util;

import android.net.Uri;
import android.provider.BaseColumns;

public class AppUtil {
	public final static String TAG = "APPUTIL";

	// totally for testing
	public final static int numDev = 1;
	// data bundle key
	public static final String KEY = "key";
	public static final String VALUE = "value";
	public static final String RESULT = "result";
	public static final String EMULATOR_IP = "10.0.2.2";
	public static final int NUM_REPLICA = 3;
	public static final int CONSOLE_PORT[] = new int[] { 5554, 5556, 5558, 5560, 5562 };
	public static final int REDIR_PORT[] = new int[] { 11108, 11112, 11116, 11120, 11124 };
	public static final int KEY_NONE_EXIST = -1;
	// server listening port number
	public static final int PORT = 10000;
	

	// Message between activity and service
	public static final int MSG_REGISTER_CLIENT = 1;
	public static final int MSG_UPDATE_VIEWLIST = 2;
	public static final int MSG_PUT_CASE = 3;
	public static final int MSG_GET_CASE = 4;
	public static final int MSG_ADD = 5;
	public static final int MSG_RERIEVE = 6;
	public static final int MSG_DISPLAY_TOAST = 7;
	// package type between each peer
	public static final String PACKAGE_DELIMITER = "/--/";
	public static final int PACKAGE_INSERT = 1;
	public static final int PACKAGE_PREPARE = 2;
	public static final int PACKAGE_ACK = 3;
	public static final int PACKAGE_COMMIT = 4;
	public static final int PACKAGE_GET = 5;
	public static final int PACKAGE_GET_RESPONSE = 6;
	public static final int PACKAGE_FAILUR_REPORT = 7;
	public static final int PACKAGE_RECOVERY_REPORT = 8;
	public static final int PACKAGE_SYN = 9;
	//type of key-value pair
	public static int KV_LOCAL_STORAGE = 1;
	public static int KV_REPLICA = 2;
	//Delimiter
	public static final String KV_LIST_DELIMITER = ";";
	public static final String KV_ATTR_DELIMITER = "_";
	
	//version number compare result
	public static final int VERSION_UNCOMPARABLE = 0;
	public static final int VERSION_BIGGER = 1;
	public static final int VERSION_SMALLER = 2;
	
	//put string
	public static final String PUT_1 = "Put1";
	public static final String PUT_2 = "Put2";
	public static final String PUT_3 = "Put3";
	
	//message key
	public static final String PUT_PRIFIX = "PUT_KEY";
	public static final String DISPLAY_RESULT = "DISPLAY_RESULT";
	// define db related info
	public static final String AUTHORITY = "edu.buffalo.cse.cse486_586.simpledynamo.provider";
	public static final String PATH = "key_value";
	public static final Uri CONTENT_URI = Uri.parse("content://"+AUTHORITY + "/" + PATH);

	public static final String DATABASE_NAME = "key_value.db";
	public static final int DATABSE_VERSION = 1;

	public static final String CONTENT_TYPE_ARTICLES_LIST = "vnd.android.cursor.dir/vnd.simpledht.key_value";
	public static final String CONTENT_TYPE_ARTICLE_ONE = "vnd.android.cursor.item/vnd.simpledht.key_value";

	public class KeyValueTable implements BaseColumns {
		private KeyValueTable() {
		}

		public static final String KV_TABLE = "key_value_tbl";
		public static final String COL_ID = "_id";
		public static final String COL_PROVIDER_KEY = "provider_key";
		public static final String COL_PROVIDER_VALUE = "provider_value";
		public static final String COL_PROVIDER_VERSION = "provider_version";
	}
	
	public static int getRedirPortByConsolePort(int p){
		int r = -1;
		for (int i=0; i<REDIR_PORT.length;i++) {
			if( CONSOLE_PORT[i] == p ){
				r =  REDIR_PORT[i];
				break;
			}
		}
		
		return r;
	}
}
